using System;
using System.Web.UI.WebControls;
using WCSFContrib.PageFlow;
using XmlPageFlowWithShoppingCartQuickstart.Store.BusinessLogic;
using Page=System.Web.UI.Page;

public partial class BrowseCatalog : Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			catalogGridView.DataSource = Controller.GetProductsCatalog();
			catalogGridView.DataKeyNames = new string[1] {"ProductId"};
			catalogGridView.DataBind();
		}
	}

	public StoreController Controller
	{
		get { return new StoreController(PageFlowDirectory.Provider); }
	}

	protected void catalogGridView_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		int rowIndex = int.Parse(e.CommandArgument.ToString());
		int productId = (int) catalogGridView.DataKeys[rowIndex].Value;
		StoreController controller = Controller;
		controller.AddToCart(controller.GetProductById(productId), 10);
	}
}